package org.example.guavalearn.proxy;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

class Cache {
    private final Map<Object, Object> cache = new HashMap<>();

    @SuppressWarnings("unchecked")
    public <K, V> V get(K key, Supplier<V> create) {
        if (cache.containsKey(key)) {
            return (V) cache.get(key);
        }
        V value = create.get();
        cache.put(key, value);
        return value;
    }
}
